<template>
  <div class="yao">
    <div class="input">
      <input placeholder="请输入想要查询的药品" @click="gosearch">
      <span class="sousuo" @click="gosearch">搜索</span>
    </div>



    <div class="item" v-for="(item,index) in list" :key="index">
      <!-- 一级 -->
      <div class="head">
        <div class="head-l">
          {{item.name}}
        </div>
      </div>
      <!-- 二级 -->
      <div class="zhong">
        <div :class="(secondClass == ind && activeid == index)?'active':''" v-for="(ite,ind) in item.sons" :key="ind" @click="getsecond(index,ind,ite)" v-show="ind < 9 || (brandFold && activeid == index)">
          {{ite.name}}<img :src="(secondClass == ind && activeid == index)?'../../../static/baitankuang.png':'../../../static/tankuang.png'" alt="">
        </div>
      </div>

      <div class="foot" @click="isOpen(index)">
        <img :src="(brandFold && activeid == index)?'../../../static/meiyougengduo.png':'../../../static/gengduo.png'" alt="">{{(brandFold && activeid == index)?'收起':'查看更多'}}
      </div>

      <!-- 三级弹框 -->
      <div class="yinying" v-if="boxshow"></div>
      <div class="box" v-if="boxshow">
        <!-- <p class="cha">x</p> -->
        <div class="tit">
          {{secondtit}} <span class="cha" @click="cha">x</span>
        </div>
        <div class="small-box">
          <div :class="thirdClass == ind?'active':''" v-for="(ite,ind) in thirdlist" :key="ind" @click="getthird(ind,ite.id)">{{ite.name}}</div>
        </div>
        <div class="queren" @click="godetails">确认</div>
      </div>

    </div>
    
  </div>
</template>

<script>
  export default {
    data() {
      return {
        boxshow:false,
        brandFold:false,
        // 药品查询分类
        list:'',
        secondClass:-1,
        activeid:'',
        secondtit:'',
        thirdClass:-1,
        thirdlist:'',
        firstid:'',
        secondid:'',
        thirdid:'',
      }
    },
    created() {
      this.getlist()
    },
    mounted(){
      
    },
    methods: {
      // 药品查询分类
      getlist(){
        this.$get("api/gzh_index.php?action=yaopin_types", {
        
        }).then(res => { 
          console.log(res.data,'res')
          this.list = res.data
        }).catch(err => {
          
        });
      },
      // 查看更多   收起
      isOpen(index){
        console.log(index,index,'123456798')
        this.activeid = index
        this.brandFold = !this.brandFold
      },
      // 获取二级id   展示三级数据
      getsecond(index,ind,list){
        
        this.firstid = list.parent_id
        this.secondid = list.id
        this.secondClass = ind
        this.activeid = index
        this.secondtit = list.name
        this.thirdlist = list.sons
        this.boxshow = true
      },
      // 获取三级id  
      getthird(index,id){
        this.thirdid = id
        this.thirdClass = index
      },
      // 差号取消
      cha(){
        this.boxshow = false
        this.thirdClass = -1
        this.thirdid = ''
      },
      // 点击确认  取消弹框  跳转详情
      godetails(){
        if(this.thirdid){
          this.boxshow = false
          this.$router.push({
            name:'look-medicine-list',
            query: {firstid:this.firstid,secondid:this.secondid,thirdid:this.thirdid}
          }) 
        }else{
          this.$toast('请选择');
        }
      },
      // 跳转药品搜索
      gosearch(){
        this.$router.push({
          name:'yaopin-search'
        }) 
      },
    },
  }
</script>

<style scoped>
.yao{
  width: 100%;
}
.input {
  width: 100%;
  padding: 0 30px;
  box-sizing: border-box;
  height: 140px;
  position: relative;
  /* text-align: center; */
  background: #06A255;
}
.input input{
  width: 590px;
  height: 73px;
  border-radius: 10px;
  outline:none;
  padding: 0 10px;
  border: none;
  background: #fff;
  box-sizing: border-box;
  margin-top: 30px;
  font-size:26px;
  font-family:PingFang SC;
  font-weight:500;
  
}
.sousuo {
  font-size: 28px;
  color: #fff;
  margin-left: 15px
}

.item{
  width: 100%;
  padding: 0 30px;
  box-sizing: border-box;
  margin-top: 30px;
}
.head{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.head-l{
  font-size: 38px;
  color: #333;
  font-weight: bold;
}
.zhong{
  margin-top: 36px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  text-align: center;
}
.zhong .active{
  background: #06A255;
  color: #fff;
  border: 1PX solid #06A255;
}
.zhong div{
  /* width: 210px; */
  height: 58px;
  margin-top: 10px;
  font-size: 28px;
  color: #3a3a3a;
  border: 1PX solid #ccc;
  line-height: 58px;
  box-sizing: border-box;
  margin-right: 40px;
  padding:  0 20px;
}
.zhong div img{
  width: 9px;
  height: 17px;
  margin-left: 10px;
}
.foot{
  width: 100%;
  margin-top: 20px;
  font-size: 26px;
  text-align: center;
}
.foot img{
  width: 20px;
  height: 10px;
  margin-right: 10px;
  vertical-align:middle;
}



/* 弹框 */
.box{
  width: 690px;
  height: 800px;
  background: #fff;
  border: 1PX solid #ccc;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  padding: 0 30px;
  box-sizing: border-box;
  border-radius: 20px;
}

.box .tit{
  width: 100%;
  text-align: center;
  font-size: 32px;
  color:#333;
  position: relative;
  height: 80px;
  line-height: 80px;
}
.box .cha{
  display: inline-block;
  font-size: 45px;
  position: absolute;
  right: 10px;
  bottom: 5px;
 
}
.box .small-box{
  width: 100%;
  height: 75%;
  display: flex;
  align-items: center;
  align-content:flex-start;
  flex-wrap: wrap;
  overflow: hidden;
  overflow-y: scroll;
  margin-top: 10px;
}
.box .small-box div{
  height: 60px;
  text-align: center;
  font-size: 28px;
  margin-top: 10px;
  line-height: 60px;
  color: #3a3a3a;
  border: 1PX solid #ccc;
  padding: 0 20px;
  box-sizing: border-box;
  margin-right: 40px;
}
.box .small-box .active{
  background: #06A255;
  color: #fff;
  border: 1PX solid #06A255;
}
.box .queren{
  width: 560px;
  height: 80px;
  background: #06A255;
  color: #333;
  text-align: center;
  line-height: 80px;
  font-size: 36px;
  border-radius: 40px;
  position: absolute;
  left: 60px;
  bottom: 20px;
  color: #fff;
}
.yinying{
  width: 100%;
  height: 100%;
  background: #000;
  opacity: .5;
  position: fixed;
  left: 0;
  top: 0;
}
</style>
<style>

</style>